using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace PeDALS.Utilities
{
    public class FileHelper
    {
        public static string GetFileNameFromPath(string path)
        {
            string[] temp;
            temp = path.Split('/');
            return temp[temp.Length - 1].ToString();
        }

        public static string GetPathFromFileName(string path)
        {
            string fullPath="";
            string[] temp;
            temp = path.Split('\\');

            for (int i = 0; i < temp.Length - 1; i++)
            {
                if (i == 0)
                    fullPath = temp[i].ToString();
                else
                    fullPath = fullPath + "\\" + temp[i].ToString();
            }

            return fullPath;

        }

        public static void DeleteIncomingFiles(string outgoingDir, string incomingDir)
        {
            /*string[] files = System.IO.Directory.GetFiles(outgoingDir);

            foreach (string file in files)
            {
                string fileName = Path.GetFileName(file);

                if(File.Exists(incomingDir + "\\data\\" + fileName))
                {
                    File.Delete(incomingDir + "\\data\\" + fileName);

                    string xmlFile = Path.GetFileNameWithoutExtension(fileName) + ".xml";

                    File.Delete(incomingDir + "\\data\\" + xmlFile);
                }
            }

            */

            //If there are no files in DATA folder, delete it
            System.IO.Directory.Delete(incomingDir + "\\data", true);

            //Delete NZME and Manifest files
            string[] files = System.IO.Directory.GetFiles(incomingDir);

            foreach (string inputfile in files)
            {
                File.Delete(inputfile);
            }
        }
    }
}
